<template>
  <div class="shop">
    <div class="common">
      <div class="common-input">
        <el-input
          v-model="commonValue"
          placeholder="店铺名称/手机号码"
          clearable
        ></el-input>
      </div>

      <div class="common-button" @click="searchHit">搜索</div>
      <div
        class="common-button"
        style="background: #999"
        @click="replacementHit"
      >
        重置(暂无数据)
      </div>
    </div>

    <div class="table" v-loading="loading">
      <el-table
        :data="tableData"
        border
        :header-cell-style="{
          color: '#333333',
          backgroundColor: '#f3f3f3',
        }"
      >
        <el-table-column prop="" label="店铺图标" align="center" width="150">
          <template slot-scope="scope">
            <img class="imgs" :src="scope.row.shopIcon" alt="" />
          </template>
        </el-table-column>
        <el-table-column prop="shopId" label="店铺ID" width="150">
        </el-table-column>
        <el-table-column prop="shopName" label="店铺名称" width="200">
        </el-table-column>
        <el-table-column prop="" label="店铺类别" width="150">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.shopType == 0" type="info">体验店铺</el-tag>
            <el-tag v-if="scope.row.shopType == 1" type="success"
              >正式店铺</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="店铺状态" width="150">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.shopStatus == -1" type="info"
              >待激活</el-tag
            >
            <el-tag v-if="scope.row.shopStatus == 0">待转正</el-tag>
            <el-tag v-if="scope.row.shopStatus == 1" type="success"
              >已入驻</el-tag
            >
            <el-tag v-if="scope.row.shopStatus == 2" type="warning"
              >待复活</el-tag
            >
            <el-tag v-if="scope.row.shopStatus == 3" type="danger"
              >已剔除</el-tag
            >
            <el-tag v-if="scope.row.shopStatus == 4" type="error"
              >彻底剔除</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="" label="店铺激活时间" width="150">
        </el-table-column>
        <el-table-column prop="" label="激活内均日贡献值" width="250">
        </el-table-column>
         <el-table-column prop="" label="激活内总贡献值" width="250">
        </el-table-column>
         <el-table-column prop="" label="天池总分成" width="150">
        </el-table-column>
         <el-table-column prop="" label="周池总分成" width="150">
        </el-table-column>
         <el-table-column prop="复活次数" label="" width="150">
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="250">
          <template slot-scope="scope">
            <div class="operation">
              <div
                class="list"
                @click.prevent="isDeleteHit(scope.row)"
              >
                可复活剔除
              </div>

              <div class="list" @click.prevent="deleteHit(scope.row)">不可复活剔除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="tableDataTotal"
          :current-page="page"
        >
        </el-pagination>
      </div>
    </div>

    <!--新增或者编辑-->
    <div class="add">
      <el-dialog
        title="剔除"
        :visible.sync="addVisible"
        :before-close="addClose"
        width="30%"
      >
        <div class="add-form">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="140px"
            class="demo-ruleForm"
          >
            <el-form-item label="剔除理由" prop="text">
              <el-input
                type="textarea"
                :rows="4"
                v-model="ruleForm.text"
                placeholder="请输入剔除理由"
              ></el-input>
            </el-form-item>

            <el-form-item class="attachment">
              <div class="list" @click="addClose">取消</div>
              <div class="list" @click="addConfirm('ruleForm')">通过</div>
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { shopList, shopListDelete } from "@/api/shop";

export default {
  data() {
    return {
      commonValue: "",
      //-------------
      page: 1,
      limit: 10,
      tableData: [],
      tableDataTotal: 0,
      dataObj: {},
      loading: false,
      commonObj: {},
      multipleSelection: [],
      //------
      addVisible: false,
      ruleForm: {
        text: "",
      },
      rules: {
        text: [{ required: true, message: "请输入剔除理由", trigger: "blur" }],
      },
    };
  },
  created() {
    this.loading = true;

    this.shopListMet();
  },
  methods: {
    shopListMet() {
    //   let params = {
    //     keyWord: this.commonValue,
    //     startTime: this.commonStart,
    //     endTime: this.commonEnd,
    //     pageSize: this.limit,
    //     pageNo: this.page,
    //   };

    //   shopList(params).then((res) => {
    //     if (res.errorCode == null) {
    //       this.dataObj = res.resultData;

    //       res.resultData.shopList.forEach((item, index) => {
    //         item.earningsPrice = Number(item.earningsPrice / 100);
    //         item.bigEarningsPrice = Number(item.bigEarningsPrice / 100);
    //         item.totalEarningsPrice = Number(item.totalEarningsPrice / 100);
    //       });

    //       this.tableData = res.resultData.shopList;
    //       this.tableDataTotal = res.resultData.totalNum;
          this.loading = false;
    //     }
    //   });
    },
    timeData(date) {
      return date.toLocaleString("zh-CN", {
        year: "numeric",
        month: "2-digit",
        day: "2-digit",
        // hour: "2-digit",
        // minute: "2-digit",
        // second: "2-digit",
      });
    },
    //-------
    searchHit() {
      if (this.commonDate.length > 0) {
        this.commonStart = this.timeData(new Date(this.commonDate[0]));
        this.commonEnd = this.timeData(new Date(this.commonDate[1]));
      } else {
        this.commonStart = "";
        this.commonEnd = "";
      }

      this.loading = true;
      this.shopListMet();
    },
    replacementHit() {
      this.commonValue = "";
      this.commonDate = [];
      this.commonStart = "";
      this.commonEnd = "";

      this.loading = true;
      this.shopListMet();
    },
    //---------
    isDeleteHit(item) {
      if (this.$store.state.premissions.infoRouterShow == false) {
        this.$message.error("暂无权限，请联系管理员开通");
        return;
      }

      this.commonObj = item;
      this.addVisible = true;
    },
    //--------

    deleteHit(item) {
      if (this.$store.state.premissions.infoRouterShow == false) {
        this.$message.error("暂无权限，请联系管理员开通");
        return;
      }
      this.commonObj = item;
      this.addVisible = true;
    },
    addClose() {
      this.addVisible = false;
    },
    addConfirm(formName) {
      this.$refs[formName].validate((valid) => {

        return
        if (valid) {
          let params = {
            shopId: this.commonObj.shopId,
            eliminateBreak: this.ruleForm.text,
          };

          shopListDelete(params).then((res) => {
            if (res.errorCode == null) {
              this.addVisible = false;
              this.$message.success("剔除成功！");
              this.loading = true;
              this.shopListMet();
            }
          });
        } else {
          return false;
        }
      });
    },
       //---------
    handleSizeChange(val) {
      this.limit = val;
      this.loading = true;
      this.shopListMet();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.loading = true;
      this.shopListMet();
    },
  },
};
</script>

<style lang="less" scoped>
@import url("@/assets/css/delete.less");

.shop {
  .common {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    .common-input {
      margin-right: 10px;
      /deep/ .el-input {
        width: 250px;
      }
    }

    .common-input:last-child {
      margin-right: 0;
    }

    .common-button {
      padding: 9px 20px;
      box-sizing: border-box;
      border-radius: 5px;
      background: #2a82e4;
      font-size: 14px;
      color: #fff;
      margin-left: 20px;
      cursor: pointer;
    }

    .common-button:last-child {
      background: #999999;
    }

    .common-title {
      margin-left: 130px;
    }
  }

  .table {
    cursor: pointer;

    .operation {
      display: flex;
      align-items: center;
      color: #2a82e4;

      .list {
        margin-right: 20px;
        cursor: pointer;
      }
    }

    .imgs {
      width: 50px;
      height: 50px;
    }
  }

  .add,
  .uploading {
    /deep/ .el-dialog__header {
      font-size: 16px;
      text-align: center;
    }

    /deep/ .el-dialog__body {
      padding-bottom: 10px;
    }

    .add-form {
      /deep/ .el-select {
        width: 100%;
      }

      .img {
        width: 70px;
        height: 70px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid #ccc;
        border-radius: 5px;

        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }

      .attachment {
        margin-top: 50px;
        /deep/ .el-form-item {
          margin-bottom: 0;
        }

        /deep/ .el-form-item__content {
          margin-left: 0 !important;
          display: flex;
          align-items: center;
          justify-content: center;
        }

        .list {
          background: #3da8f5;
          color: #fff;
          font-size: 16px;
          margin-right: 50px;
          border-radius: 5px;
          width: 100px;
          height: 35px;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
        }

        .list:first-child {
          background: #808080;
        }

        .list:last-child {
          margin-right: 0;
        }
      }
    }
  }
}
</style>